﻿/**
 * LineStyle
 *
 * @author		Allen Chou
 * @version		1.0.1 (last update: Nov 19 2008)
 * @link        http://cjcat.blogspot.com
 * @link		http://cjcat2266.deviantart.com
 */

package idv.cjcat.display {

	/**
	 * The <code>LineStyle</code> class lets you store all the information required
	 * when using <code>flash.display.Graphics.lineStyle()</code> in a single object,
	 * which can be conveniently reused.
	 * 
	 * <p>
	 * Use <code>LineStyle</code> through <code>CJDisplay.lineStyle()</code> to set the
	 * line style of the <code>Graphics</code> object of a <code>Shape</code> or <code>Sprite</code>.
	 * </p>
	 * 
	 * @example
	 * <listing>
	 * //original lineStyle() usage
	 * clip1_mc.graphics.lineStyle(thickness, color, alpha, pixelHinting, scaleMode, caps, joints, miterLimit);
	 * clip2_mc.graphics.lineStyle(thickness, color, alpha, pixelHinting, scaleMode, caps, joints, miterLimit);
	 * clip3_mc.graphics.lineStyle(thickness, color, alpha, pixelHinting, scaleMode, caps, joints, miterLimit);
	 * 
	 * //equivalent using LineStyle and CJGraphics
	 * var lineStyle:LineStyle = new LineStyle(thickness, color, alpha, pixelHinting, scaleMode, caps, joints, miterLimit);
	 * CJDisplay.lineStyle(clip1_mc, lineStyle);
	 * CJDisplay.lineStyle(clip2_mc, lineStyle);
	 * CJDisplay.lineStyle(clip3_mc, lineStyle);</listing>
	 */
	public class LineStyle {
		
		/**
		 * Line thickness.
		 */
		public var thickness:Number;
		/**
		 * Line color.
		 */
		public var color:uint;
		/**
		 * Line alpha.
		 */
		public var alpha:Number;
		/**
		 * Whether uses pixel hinting.
		 */
		public var pixelHinting:Boolean;
		/**
		 * A value from the <code>flash.display.LineScaleMode</code> class that specifies which scale mode to use:
		 * <ul>
		 * <li><code>LineScaleMode.NORMAL</code>—Always scale the line thickness when the object is scaled (the default).</li>
		 * <li><code>LineScaleMode.NONE</code>—Never scale the line thickness.</li>
		 * <li><code>LineScaleMode.VERTICAL</code>—Do not scale the line thickness if the object is scaled vertically <i>only</i>.</li>
		 * <li><code>LineScaleMode.HORIZONTAL</code>—Do not scale the line thickness if the object is scaled horizontally <i>only</i>.</li>
		 * </ul>
		 */
		public var scaleMode:String;
		
		/**
		 * A value from the <code>CapsStyle</code> class that specifies the type of caps at the end of lines.
		 * Valid values are: <code>CapsStyle.NONE</code>, <code>CapsStyle.ROUND</code>, and <code>CapsStyle.SQUARE</code>. 
		 */
		public var caps:String;
		/**
		 * A value from the <code>flash.display.JointStyle</code> class that specifies the type of joint appearance used at angles.
		 * Valid values are: <code>JointStyle.BEVEL</code>, <code>JointStyle.MITER</code>, and <code>JointStyle.ROUND</code>.
		 * If a value is not indicated, Flash uses round joints. 
		 */
		public var joints:String;
		/**
		 * A number that indicates the limit at which a miter is cut off.
		 * Valid values range from 1 to 255 (and values outside that range are rounded to 1 or 255). 
		 */
		public var miterLimit:Number;
		
		public function LineStyle(thickness:Number = 0,
								  color:uint = 0x000000,
								  alpha:Number = 1,
								  pixelHinting:Boolean = false,
								  scaleMode:String = "normal",
								  caps:String = null,
								  joints:String = null,
								  miterLimit:Number = 3) {
			
			this.thickness = thickness;
			this.color = color;
			this.alpha = alpha;
			this.pixelHinting = pixelHinting;
			this.scaleMode = scaleMode;
			this.caps = caps;
			this.joints = joints;
			this.miterLimit = miterLimit;
		}
		
		/**
		 * Returns a copy of itself.
		 * @return The copy.
		 */
		public function clone():LineStyle {
			return new LineStyle(this.thickness, this.color, this.alpha, this.pixelHinting, this.scaleMode, this.caps, this.joints, this.miterLimit);
		}
		
	}
}